<?php

/* ========================================================================= */
/* This file is part of the HypnoPHP Framework Library                       */
/* Copyright (c) 2009-2010, Radu Buzea                                       */
/* ========================================================================= */

/**
* @author Radu Buzea
* @copyright Copyright (c) 2009-2010, Radu Buzea (www.hypnosis.ro)
* @license GNU Lesser General Public License (www.gnu.org/copyleft/lesser.html)
* @package HypnoPHP
* @category Core
* @version 1.0.3
*/

defined('HYPNOPHP_APPLICATION') or
die("Cannot use <i>" . basename(__FILE__) . "</i> outside HypnoPHP Application");

// ============================================================================
// Class: HBaseHelper
// ============================================================================

abstract class HBaseHelper extends HBaseObject
{
	protected $__content = '';
	protected $__parent_controller = null;
	protected $__parent_view = null;

	# ###########################################################################

	/**
	* Initialize object properties
	*
	* @return void
	*/
	public function __initialize()
	{
		$this->__content = '';
		$this->__parent_controller = null;
		$this->__parent_view = null;
		if (func_num_args() > 0) {
			$args = func_get_arg(0);
			if (is_array($args) && isset($args[0]) && is_object($args[0])) {
				$this->__parent_controller = $args[0];
			}
		}
		if (method_exists($this, 'run')) { $this->run(); }
	}

	# ###########################################################################

	/**
	* Get the parent controller objec from which the controller was initalized
	*
	* @param HBaseController $controller
	* @return bool (on set new parent controller) or HBaseController
	*/
	public function parentController($controller = null)
	{
		if (!is_null($controller)) {
			if (is_object($controller)) {
				$this->__parent_controller = $controller;
				return true;
			}
			return false;
		}
		return $this->__parent_controller;
	}

	# ###########################################################################

	/**
	* Get the parent view objec from which the controller was initalized
	*
	* @param HBaseView $view
	* @return bool (on set new parent controller) or HBaseView
	*/
	public function parentView($view = null)
	{
		if (!is_null($view)) {
			if (is_object($view)) {
				$this->__parent_view = $view;
				return true;
			}
			return false;
		}
		return $this->__parent_view;
	}

	# ###########################################################################

	/**
	* Set the helper output content
	*
	* @param string $content
	* @return void
	*/
	public function setContent($content = '')
	{
		$this->__content = $content;
	}

	# ###########################################################################

	/**
	* Append content to the helper output content
	*
	* @param string $content
	* @param bool $before Apend before or after the original content
	* @return void
	*/
	public function appendContent($content = '', $before = false)
	{
		if ($before) { $this->__content = $content . $this->__content; }
		else { $this->__content = $this->__content . $content; }
	}

	# ###########################################################################

	/**
	* Get the helper content
	*
	* @return string
	*/
	public function output()
	{
		return $this->__content;
	}

	# ###########################################################################

}
